function new_ajax() 
{
    var ajax;
    
    try
    {  
        ajax = new XMLHttpRequest();
    }
    catch( e )
    {
        var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                        "MSXML2.XMLHTTP.5.0",
                                        "MSXML2.XMLHTTP.4.0",
                                        "MSXML2.XMLHTTP.3.0",
                                        "MSXML2.XMLHTTP",
                                        "Microsoft.XMLHTTP");
        
        for( var i = 0; i < XmlHttpVersions.length && !ajax; i++ )
        {
            try
            {
                ajax = new ActiveXObject( XmlHttpVersions[i] );
            }
            catch( e )
            {}
        }
    }
    
    if ( !ajax )
    {
        alert("Can't create XMLHTTPRequest, please, update your browser.");
    }
    else
    {
        return ajax;
    }
}

function makeInput( element )
{
    var element_one = document.getElementById( 'ajax_' + element );
    var element_two = document.getElementById( 'input_' + element );
    var element_three = document.getElementById( 'element_' + element );
    var element_four = document.getElementById( 'form_' + element );
    
    element_one.style.display = 'none';
    element_two.style.display = 'block';
}

function declineInput( element )
{
    var element_one = document.getElementById( 'ajax_' + element );
    var element_two = document.getElementById( 'input_' + element );
    
    element_one.style.display = 'block';
    element_two.style.display = 'none';
}

function saveProfileData( element, params )
{
    var ajax = new_ajax();
    
    ajax.open( 'POST', 'ajax.php?mode=profile' );
    ajax.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );
    ajax.setRequestHeader( 'Content-length', params.length );
    ajax.setRequestHeader( 'Connection', 'close' );
    
    ajax.onreadystatechange = function()
    {
        if( ajax.readyState == (0||1) )
        {
            document.getElementById( 'ajaxLoading' ).style.display = 'block';
        }
        else if( ajax.readyState == 4 )
        {
            var split = ajax.responseText.split( '|' );
            
            document.getElementById( 'ajaxLoading' ).style.display = 'none';
            
            if( split[1] != undefined )
            {
                alert( split[1] );
            }
            else
            {
                declineInput( element );
                document.getElementById( 'element_' + element ).innerHTML = ajax.responseText;
            }
        }
    }
    ajax.send(params);
}